package com.csxy.lsh.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.csxy.lsh.entity.CrmBanner;
import com.csxy.lsh.entity.vo.BannerQuery;
import com.csxy.lsh.mapper.CrmMapper;
import com.csxy.lsh.service.CrmService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CrmServiceImpl extends ServiceImpl<CrmMapper, CrmBanner> implements CrmService {
    @Autowired
    private CrmMapper crmMapper;

    @Override
    public void pageQuery(Page<CrmBanner> bannerPage, BannerQuery bannerQuery) {
        QueryWrapper<CrmBanner> wrapper = new QueryWrapper<>();
        if (bannerQuery != null) {
            if (bannerQuery.getName() != null && !"".equals(bannerQuery.getName())) {
                wrapper.like("title", bannerQuery.getName());
            }
            if (!StringUtils.isEmpty(bannerQuery.getBegin())) {
                wrapper.ge("gmt_create", bannerQuery.getBegin());
            }
            if (!StringUtils.isEmpty(bannerQuery.getEnd())) {
                wrapper.le("gmt_modified", bannerQuery.getEnd());
            }
        }
        crmMapper.selectPage(bannerPage, wrapper);
    }

    @Cacheable(value = "banner", key = "'getAllBanner'")
    @Override
    public List<CrmBanner> getAllBanner() {
        List<CrmBanner> list = baseMapper.selectList(null);

        return list;
    }
}


